<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="工单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrderId">
              <a-input v-model="model.workOrderId" placeholder="请输入工单ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工艺路线ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="routeDetailId">
              <a-input v-model="model.routeDetailId" placeholder="请输入工艺路线ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seqNo">
              <a-input-number v-model="model.seqNo" placeholder="请输入序号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processNo">
              <a-input v-model="model.processNo" placeholder="请输入工序编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processName">
              <a-input v-model="model.processName" placeholder="请输入工序名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作中心" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workId">
              <a-input v-model="model.workId" placeholder="请输入工作中心"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="pp_process_status" placeholder="请选择工序状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加工数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qty">
              <a-input-number v-model="model.qty" placeholder="请输入加工数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合格数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="completeQty">
              <a-input-number v-model="model.checkQty" placeholder="请输入合格数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报废数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scrapQty">
              <a-input-number v-model="model.scrapQty" placeholder="请输入报废数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="返修数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reworkQty">
              <a-input-number v-model="model.reworkQty" placeholder="请输入返修数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="面积" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="areaNum">
              <a-input-number v-model="model.areaNum" placeholder="请输入面积" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="重量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weight">
              <a-input-number v-model="model.weight" placeholder="请输入重量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划开工期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="planStartDate">
              <j-date placeholder="请选择计划开工期" v-model="model.planStartDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际开工期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actStartDate">
              <j-date placeholder="请选择实际开工期" v-model="model.actStartDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划完工期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="planEndDate">
              <j-date placeholder="请选择计划完工期" v-model="model.planEndDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际完工期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actEndDate">
              <j-date placeholder="请选择实际完工期" v-model="model.actEndDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标准工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standardTime">
              <a-input-number v-model="model.standardTime" placeholder="请输入标准工时" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="准备工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prepareTime">
              <a-input-number v-model="model.prepareTime" placeholder="请输入准备工时" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="等待工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waitTime">
              <a-input-number v-model="model.waitTime" placeholder="请输入等待工时" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工时单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeUnit">
              <j-dict-select-tag type="list" v-model="model.timeUnit" dictCode="pp_process_time_unit" placeholder="请选择工时单位" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="租户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">
              <a-input v-model="model.tenantId" placeholder="请输入租户ID"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'PpWorkOrderProcessForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            status:"01",
            timeUnit:"hour",
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/pp/workOrderProcess/add",
          edit: "/pp/workOrderProcess/edit",
          queryById: "/pp/workOrderProcess/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
